package com.example.newjiesai;

import com.example.newjiesai.netty.TcpServer;
import com.example.newjiesai.util.BaiduAPI;
import com.example.newjiesai.util.FormatUtil;
import com.example.newjiesai.util.GPSUtil;
import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import io.netty.channel.ChannelFuture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;

import javax.xml.bind.DatatypeConverter;
import java.net.InetSocketAddress;

@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringCloudApplication
public class NewjiesaiApplication implements CommandLineRunner {        //实现一些预先数据的加载

    int port = 35250;

//    int port = 35269;
    @Autowired
    private TcpServer tcpServer;

    public static void main(String[] args) {

        SpringApplication.run(NewjiesaiApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {


       // String s = "\r\n";
      //  System.out.println("长度： "+s.length());   //长度为2

        /*
        String gps_lat = "28.115341";
        String gps_lon = "113.02721";

        String gps_pot = BaiduAPI.getLocName(gps_lat, gps_lon);
        //String gps_pot = BaiduAPI.getLocName("37°55’56.6″","114°65’24.6″");          //就直接输，不需要转啊
        System.out.println("-------------------");
        System.out.println(gps_pot);\

         */


        //System.out.println("\r\n");
        //System.out.println("-------");

/*
        byte[] resultByte = {(byte)0xAA, (byte)0xBB};
        String resultHex = DatatypeConverter.printHexBinary(resultByte);    //将字节数组编码为16进制字符串输出
        String b = FormatUtil.bytesToHex(resultByte);                    //也是将字节数组编码为16进制字符串输出
        System.out.println(resultHex);
        System.out.println(b);
        System.out.println(resultByte.toString());

 */

        System.out.println("TCPSERVER启动");
        InetSocketAddress address = new InetSocketAddress( port );
        ChannelFuture future = tcpServer.start(address);

        Runtime.getRuntime().addShutdownHook(new Thread(){
            @Override
            public void run() {
                tcpServer.destroy();
            }
        });

        future.channel().closeFuture().syncUninterruptibly();

    }

}
